//
//  OrdersListTableViewCell.m
//  YueYueSpecailCarDriver
//
//  Created by DL on 17/1/9.
//  Copyright © 2017年 黄旺鑫. All rights reserved.
//

#import "OrdersListTableViewCell.h"
#import <QXDriverConfiguration/QXDriverConfiguration.h>
#import "OrdersListModel.h"
#import "HeaderMacro.h"
@implementation OrdersListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.timeImageView.image = [QXDriverConfiguration imageWithName:@"puclic_time_gray"];
    
    self.backView.layer.cornerRadius = 3.0;
    self.backView.layer.masksToBounds = YES;
    
    self.startImageView.layer.cornerRadius = 2.5;
    self.startImageView.layer.masksToBounds = YES;
    
    self.endImageView.layer.cornerRadius = 2.5;
    self.endImageView.layer.masksToBounds = YES;
    
    self.typeLabel.layer.cornerRadius = 4.0;
    self.typeLabel.layer.borderColor = [UIColor colorWithRed:140 / 255.0 green:159 / 255.0 blue:183 / 255.0 alpha:1.0].CGColor;
    self.typeLabel.layer.borderWidth = 1.0;
    self.typeLabel.layer.masksToBounds = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setValueWithOrdersListModel:(OrdersListModel *)model {
    
    // 设置时间,时间格式为: HH:mm
    if (model.deparTime) {
        
        self.timeLabel.text = [NSString stringWithFormat:@"%@" , [self formatTimeStamp:model.deparTime withTimeFormatter:@"HH:mm"]];
    }else {
        
        self.timeLabel.text = @" ";
    }
    
    // 配置订单类型
    if (model.typeTime) {
        
        NSString *typeTime;
        switch (model.typeTime) {
            case 1: {
             
                typeTime = [NSString stringWithFormat:@"  %@  " , @"实时订单"];
                self.typeLabel.hidden = YES;
                break;
            }
            case 2: {
                
                typeTime = [NSString stringWithFormat:@"  %@  " , @"预约订单"];
                self.typeLabel.hidden = NO;
                break;
            }
            case 3:
            case 4: {
                
                typeTime = [NSString stringWithFormat:@"  %@  " , @"包车"];
                self.typeLabel.hidden = NO;
                break;
            }
            default: {
                
                typeTime = @" ";
                self.typeLabel.hidden = YES;
                break;
            }
        }
        
        self.typeLabel.text = typeTime;
    }else {
        
        self.typeLabel.text = @" ";
    }
    
    // 价格
    if (model.totalFare) {
        
        self.fareLabel.text = [NSString stringWithFormat:@"￥%.1f " , model.totalFare];
    }else {
        
        self.fareLabel.text = @"";
    }
    
    // 状态
    if (model.subStatus) {
        
        self.statusLabel.text = [self returnStateStringWithStateNumber:model.subStatus];
    }else {
        
        self.statusLabel.text = @"";
        self.fareLabel.text = @"";
    }
    
    
    
    if (![model.originAddress isKindOfClass:[NSNull class]]) {
        
        self.startLabel.text = model.originAddress;
    }else {
        
        self.startLabel.text = @"";
    }
    
    if (![model.destAddress isKindOfClass:[NSNull class]]) {
        
        self.endLabel.text = model.destAddress;
    }else {
        
        self.endLabel.text = @"";
    }
}

/**
 *  将时间戳转为指定格式的时间
 */
- (NSString *)formatTimeStamp:(NSTimeInterval)timeStamp withTimeFormatter:(NSString *)timeFormatters
{
    //秒数
    NSTimeInterval interval = timeStamp / 1000.0;
    //date
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    //格式
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:timeFormatters];
    //时间
    NSString *timeStr = [format stringFromDate:date];
    
    return timeStr;
}


/**
 返回订单状态

 @param stateNumber 订单状态代码
 @return 订单状态文字描述
 */
- (NSString *)returnStateStringWithStateNumber:(NSInteger)stateNumber {
    
    NSString *stateString;
    switch (stateNumber) {
            
        case OrderStatusCode_DriverReceivedOrder_DetermineStroke:
        {
            
            stateString = @"未开始";
            self.statusLabel.textColor = [UIColor whiteColor];
            self.fareLabel.textColor = [UIColor whiteColor];
            break;
        }
        case OrderStatusCode_DriverSetOut_GoToPickUpPassengers: // 210［去接乘客］司机出发、去接乘客 . ［出租／专车］
        case OrderStatusCode_DriverArrived_WaitingForPassengers: // 220［等待乘客］司机到达、等待乘客 . ［出租／专车
        case OrderStatusCode_PickedUpPasengers_StrokeStart: // 进行中  300：［行程开始］乘客上车、行程开始 . ［出租／专车／拼车］
        case OrderStatusCode_PassengersArrivedDestination: // 400：［行程结束］司机送达目的地 ,这时候显示催款,提现页面
        {
            
            stateString = @"进行中";
            self.statusLabel.textColor = [UIColor whiteColor];
            self.fareLabel.textColor = [UIColor whiteColor];
            break;
        }
        case OrderStatusCode_DriverConfirmFare_WaitingForPassengersToPay: // 500：司机确认费用，等待乘客支付
        case OrderStatusCode_StrokeDetermination_PassengerCancelOrder_WaitingForPassengersToPayCancleFare: // 511：［行程确定］乘客取消，待支付取消费用
        case OrderStatusCode_StrokeDetermination_DriverCancelOrder_WaitingForPassengersToPayCancleFare: // 521：［行程确定］司机取消，待支付取消费用
        case OrderStatusCode_GotoPickUpPassengers_PassengerCancelOrder_WaitingForPassengersToPayCancleFare: // 512：［去接乘客］乘客取消，待支付取消费用
        case OrderStatusCode_GotoPickUpPassengers_DriverCancelOrder_WaitingForPassengersToPayCancleFare: // 522：［去接乘客］司机取消，待支付取消费用
        case OrderStatusCode_WaitingForPassengers_PassengerCancelOrder_WaitingForPassengersToPayCancleFare: // 513：［等待乘客］乘客取消，待支付取消费用
        case OrderStatusCode_WaitingForPassengers_DriverCancelOrder_WaitingForPassengersToPayCancleFare: // 523：［等待乘客］司机取消，待支付取消费用
        {
            
            stateString = @"待支付";
            self.statusLabel.textColor = [UIColor whiteColor];
            self.fareLabel.textColor = [UIColor whiteColor];
            break;
        }
        case OrderStatusCode_PaymentCompleted_StrokeOver: // 600：付款完成、行程结束 , 不显示催款,提现页面
        case OrderStatusCode_PassengersHasCompletedEvaluationForDriver: // 610：乘客完成对车主评价 , 不显示催款,提现页面
        {
            
            stateString = @"已支付";
            self.statusLabel.textColor = Color_8c9fb8;
            self.fareLabel.textColor = Color_8c9fb8;
            break;
        }
        case OrderStatusCode_NewStroke_PassengerCancel: // 900：［新行程］乘客取消
        case OrderStatusCode_PassengersCancel_StrokeDetemination_DriverNotArrive: // 901: 乘客取消（行程确定后、司机未到达
        case OrderStatusCode_PassengersCancel_StrokeDetemination_DriverArrived: // 902: 乘客取消（行程确定后、司机到达）
        case OrderStatusCode_NewStroke_DriverCancel: // 910：［新行程］司机取消
        case OrderStatusCode_NoFare_StrokeDetermination_PassengersCancelOrder: // 90200：［无费用］［行程确定］乘客取消订单
        case OrderStatusCode_NoFare_GotoPickUpPassengers_PassengersCancelOrder: // 90210：［无费用］［去接乘客］乘客取消订单
        case OrderStatusCode_NoFare_WaitingForPassengers_PassengersCancelOrder: // 90220：［无费用］［等待乘客］乘客取消订单
        case OrderStatusCode_NoFare_StrokeDetermination_DriverCancelOrder: // 91200：［无费用］［行程确定］司机取消订单
        case OrderStatusCode_NoFare_GotoPickUpPassengers_DriverCancelOrder: // 91210：［无费用］［去接乘客］司机取消订单
        case OrderStatusCode_NoFare_WaitingForPassengers_DriverCancelOrder: // 91220：［无费用］［等待乘客］司机取消订单
        case OrderStatusCode_OrderClosedByCustomerService: // 990：客服关闭订单
        case OrderStatusCode_HaveFare_StrokeDetermination_PassengersCancelOrder: // 90511：［有费用］［行程确定］乘客取消订单
        case OrderStatusCode_HaveFare_GotoPickUpPassengers_PassengersCancelOrder: // 90512：［有费用］［去接乘客］乘客取消订单
        case OrderStatusCode_HaveFare_WaitingForPassengers_PassengersCancelOrder: // 90513：［有费用］［等待乘客］乘客取消订单
        case OrderStatusCode_HaveFare_StrokeDetermination_DriverCancelOrder: // 91521：［有费用］［行程确定］司机取消订单
        case OrderStatusCode_HaveFare_GotoPickUpPassengers_DriverCancelOrder: // 91522：［有费用］［去接乘客］司机取消订单
        case OrderStatusCode_HaveFare_WaitingForPassengers_DriverCancelOrder: // 91523：［有费用］［等待乘客］司机取消订单
        {
            
            stateString = @"已取消";
            self.statusLabel.textColor = Color_8c9fb8;
            self.fareLabel.textColor = Color_8c9fb8;
            break;
        }

        default: {
            
            stateString = @"";
            break;
        }
    }
    return stateString;
}

@end
